package com.pdg.mcplugin.spawnsurance.commandprocessors;

import org.bukkit.Material;
import org.bukkit.command.CommandSender;

import com.pdg.mcplugin.common.ArgumentList;
import com.pdg.mcplugin.common.baseclasses.CommandProcessorBase;
import com.pdg.mcplugin.spawnsurance.PermissionChecker;
import com.pdg.mcplugin.spawnsurance.SpawnSurance;

public class FilterCommandProcessor extends CommandProcessorBase<SpawnSurance> {

	private static final String ADD = "ADD";
	private static final String REMOVE = "REMOVE";
	private static final String messageSuccessAdd = "You have successfully added %s to the filter.";
	private static final String messageSuccessRemove = "You have successfully removed %s from the filter.";

	public FilterCommandProcessor(SpawnSurance thePlugin) {
		super(thePlugin, new String[]{
				"/spawnsurance filter add (material)",
				"/spawnsurance filter remove (material)"
				
		});
	}

	@Override
	protected boolean specialProcessCommand(CommandSender theCommandSender,
			String theSubCommand, ArgumentList theArgumentList) {
		if(!getPlugin().getPermissionChecker().checkPermission(theCommandSender, PermissionChecker.permissionAdminConfiguration)){
			return false;
		}
		String theValue = theArgumentList.popAll();
		Material theMaterial = Material.valueOf(theValue);
		if(theSubCommand.equalsIgnoreCase(ADD)){
			getPlugin().getPluginConfiguration().addFilterMaterial(theMaterial);
			getPlugin().sendSuccessMessage(theCommandSender, String.format(messageSuccessAdd,theMaterial.toString()));
		}else if(theSubCommand.equalsIgnoreCase(REMOVE)){
			getPlugin().getPluginConfiguration().removeFilterMaterial(theMaterial);
			getPlugin().sendSuccessMessage(theCommandSender, String.format(messageSuccessRemove,theMaterial.toString()));
		}else{
			return false;
		}
		return false;
	}

}
